<?

// Generacio d'arxius XML

class xmlgen
{
	 
	 var $xmlstr;               // xurro XML que anem generant
	 	 
	 
	 function xmlgen()
	 {
		  // Constructora
		  $this->xmlstr="";
	 }


	 function addTag($name, $cdata, $params)
	 {
		  // Afegeix un tag al xurro XML
		  // "name" conte el tag sense < / >
		  // params es un string
		  
		  if (substr_count($name, ">")>0 || substr_count($name, "<")>0 || substr_count($name, "/")>0
				|| substr_count($name, "\"")>0 || substr_count($name, "\'")>0)
		  {
				echo("ERROR XMLGEN ADDTAG!!");
				return -1; // caracter no valid!
		  }
		  if ($params==NULL)
			 $otag="<".$name;
		  else
			 $otag="<".$name." ".$params;
		  
		  if ($cdata==NULL)
			 $this->xmlstr.=$otag." />";
		  else
			 $this->xmlstr.=$otag.">".$cdata."</".$name.">";
		  
		  return 0;
	 }
	 
	 	 
	 function getXML()
	 {
		  return ($this->xmlstr);
	 }
	 
	 
	 function dumpa()
	 {
		  echo("<BR><PRE>".(htmlspecialchars($this->xmlstr))."</PRE>");
	 }


	 function ppdumpa()
	 {
		  $cad=$this->xmlstr;
		  $cad=str_replace(">", ">\n\t", $cad);
		  $cad=str_replace("<", "\n\t<", $cad);
		  $cad=htmlspecialchars($cad);
		  echo("<BR><PRE>".($cad)."</PRE>");
	 }

	 
}
?>
